package com.kingyea.mobilepolice.rolepermission.service.impl;

import com.kingyea.mobilepolice.rolepermission.bean.RolePermission;
import com.kingyea.mobilepolice.rolepermission.bean.RolePermissionCondition;
import com.kingyea.mobilepolice.rolepermission.dao.RolePermissionMapper;
import com.kingyea.mobilepolice.rolepermission.service.RolePermissionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Mr.Lin
 * @version v1.0.0
 * @description RolePermission 实现类
 * @date Created in 2018-03-30 15:32:07
 */
@Service
@Transactional
public class RolePermissionServiceImpl implements RolePermissionService {

    private static final Logger LOGGER = LoggerFactory.getLogger(RolePermissionServiceImpl.class);

    @Resource
    private RolePermissionMapper rolePermissionMapper;

    /**
     * 通过ID查找对象
     *
     * @param id
     * @return
     */
    @Override
    public RolePermission getById(Integer id) throws Exception {
        return this.rolePermissionMapper.getById(id);
    }

    /**
     * 列表
     *
     * @param
     * @return
     */
    @Override
    public List<RolePermission> search(RolePermissionCondition condition) {
        List<RolePermission> list = rolePermissionMapper.search(condition);
        return list;
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Override
    public int deleteById(Integer id) throws Exception {
        rolePermissionMapper.deleteById(id);
        return 1;
    }

    /**
     * 保存
     *
     * @param rolePermission
     * @return
     */
    @Override
    public RolePermission save(RolePermission rolePermission) throws Exception {
        try {
            rolePermissionMapper.save(rolePermission);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return rolePermission;
    }

    /**
     * 更新
     *
     * @param rolePermission
     * @return
     */
    @Override
    public RolePermission update(RolePermission rolePermission) throws Exception {
        try {
            rolePermissionMapper.update(rolePermission);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return rolePermission;
    }


}
